package small_file

import (
	"context"
	"enode/store/small_file/util"
	"time"
)

func (f *FileStore) DelAllExpireFiles(ctx context.Context) {
	for i := -1; i > -180; i-- {
		util.FolderNameAfter(i)
		f.CleanExpireFiles(ctx, util.ExpireString(i))
	}
}

func (f *FileStore) Run(ctx context.Context) {
	go func() {
		f.DelAllExpireFiles(ctx)
		tk := time.NewTimer(time.Hour * 5)
		defer tk.Stop()
		for {
			select {
			case <-tk.C:
				f.CleanExpireFiles(ctx, util.ExpireString(-1))
			case <-ctx.Done():
				break
			}
		}
	}()
}
